Socket
Socket
Sign inDemoInstall

upath

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

upath

A proxy to `path`, replacing `\` with `/` for all results & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.


Version published
Weekly downloads
12M
increased by4.94%
Maintainers
1
Weekly downloads
 
Created

What is upath?

The 'upath' npm package is a utility for working with file and directory paths across different operating systems. It provides a consistent API for handling paths, ensuring compatibility between Windows, macOS, and Linux.

What are upath's main functionalities?

Normalization

The 'normalize' function converts a given path to a consistent format, replacing backslashes with forward slashes and resolving '..' and '.' segments.

const upath = require('upath');
const normalizedPath = upath.normalize('foo\bar//baz/asdf/quux/..');
console.log(normalizedPath); // Outputs: 'foo/bar/baz/asdf'

Joining Paths

The 'join' function concatenates multiple path segments into a single path, ensuring the correct separators are used.

const upath = require('upath');
const joinedPath = upath.join('foo', 'bar', 'baz/asdf', 'quux', '..');
console.log(joinedPath); // Outputs: 'foo/bar/baz/asdf'

Resolving Paths

The 'resolve' function computes the absolute path by resolving '..' and '.' segments and considering the current working directory.

const upath = require('upath');
const resolvedPath = upath.resolve('foo/bar', '/tmp/file/', '..', 'a/../subfile');
console.log(resolvedPath); // Outputs: '/tmp/subfile'

Getting Directory Name

The 'dirname' function returns the directory name of a given path.

const upath = require('upath');
const dirName = upath.dirname('/foo/bar/baz/asdf/quux');
console.log(dirName); // Outputs: '/foo/bar/baz/asdf'

Getting Base Name

The 'basename' function returns the last portion of a path, typically the file name.

const upath = require('upath');
const baseName = upath.basename('/foo/bar/baz/asdf/quux.html');
console.log(baseName); // Outputs: 'quux.html'

Getting Extension Name

The 'extname' function returns the extension of the path, from the last occurrence of the '.' character to the end of the string.

const upath = require('upath');
const extName = upath.extname('/foo/bar/baz/asdf/quux.html');
console.log(extName); // Outputs: '.html'

Other packages similar to upath

Keywords

FAQs

Package last updated on 02 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc